/*
 * linux/include/asm-arm/arch-omap/mux.h
 *
 * Table of the Omap register configurations for the FUNC_MUX and
 * PULL_DWN combinations.
 *
 * Copyright (C) 2004 - 2008 Texas Instruments Inc.
 * Copyright (C) 2003 - 2008 Nokia Corporation
 *
 * Written by Tony Lindgren
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * NOTE: Please use the following naming style for new pin entries.
 *	 For example, W8_1610_MMC2_DAT0, where:
 *	 - W8	     = ball
 *	 - 1610	     = 1510 or 1610, none if common for both 1510 and 1610
 *	 - MMC2_DAT0 = function
 */

#ifndef __ASM_ARCH_MUX_H
#define __ASM_ARCH_MUX_H

#define PU_PD_SEL_NA		0	/* No pu_pd reg available */
#define PULL_DWN_CTRL_NA	0	/* No pull-down control needed */



#define MUX_REG(reg, mode_offset, mode) .mux_reg = FUNC_MUX_CTRL_##reg, \
					.mask_offset = mode_offset, \
					.mask = mode,

#define PULL_REG(reg, bit, status)	.pull_reg = PULL_DWN_CTRL_##reg, \
					.pull_bit = bit, \
					.pull_val = status,

#define PU_PD_REG(reg, status)		.pu_pd_reg = PU_PD_SEL_##reg, \
					.pu_pd_val = status,



#define MUX_CFG(desc, mux_reg, mode_offset, mode,	\
		pull_reg, pull_bit, pull_status,	\
		pu_pd_reg, pu_pd_status, debug_status)	\
{							\
	.name =	 desc,					\
	.debug = debug_status,				\
	MUX_REG(mux_reg, mode_offset, mode)		\
	PULL_REG(pull_reg, pull_bit, pull_status)	\
	PU_PD_REG(pu_pd_reg, pu_pd_status)		\
},


/*
 * OMAP730 has a slightly different config for the pin mux.
 * - config regs are the OMAP730_IO_CONF_x regs (see omap730.h) regs and
 *   not the FUNC_MUX_CTRL_x regs from hardware.h
 * - for pull-up/down, only has one enable bit which is is in the same register
 *   as mux config
 */

#define MUX_CFG_24XX(desc, reg_offset, mode,			\
				pull_en, pull_mode, dbg)	\
{								\
	.name		= desc,					\
	.debug		= dbg,					\
	.mux_reg	= reg_offset,				\
	.mask		= mode,					\
	.pull_val	= pull_en,				\
	.pu_pd_val	= pull_mode,				\
},

/* 24xx/34xx mux bit defines */
#define OMAP2_PULL_ENA		(1 << 3)
#define OMAP2_PULL_UP		(1 << 4)
#define OMAP2_ALTELECTRICALSEL	(1 << 5)

/* 34xx specific mux bit defines */
#define OMAP3_INPUT_EN		(1 << 8)
#define OMAP3_OFF_EN		(1 << 9)
#define OMAP3_OFFOUT_ENn	(1 << 10)
#define OMAP3_OFFOUT_VAL	(1 << 11)
#define OMAP3_OFF_PULL_EN	(1 << 12)
#define OMAP3_OFF_PULL_UP	(1 << 13)
#define OMAP3_WAKEUP_EN		(1 << 14)

/* 34xx mux mode options for each pin. See TRM for options */
#define	OMAP34XX_MUX_MODE0	0
#define	OMAP34XX_MUX_MODE1	1
#define	OMAP34XX_MUX_MODE2	2
#define	OMAP34XX_MUX_MODE3	3
#define	OMAP34XX_MUX_MODE4	4
#define	OMAP34XX_MUX_MODE5	5
#define	OMAP34XX_MUX_MODE6	6
#define	OMAP34XX_MUX_MODE7	7

/* 34xx active pin states */
#define OMAP34XX_PIN_OUTPUT		0
#define OMAP34XX_PIN_OUTPUT_PULLUP	(OMAP2_PULL_ENA | OMAP2_PULL_UP)
#define OMAP34XX_PIN_OUTPUT_PULLDOWN	OMAP2_PULL_ENA

#define OMAP34XX_PIN_INPUT		OMAP3_INPUT_EN
#define OMAP34XX_PIN_INPUT_PULLUP	(OMAP2_PULL_ENA | OMAP3_INPUT_EN \
						| OMAP2_PULL_UP)
#define OMAP34XX_PIN_INPUT_PULLDOWN	(OMAP2_PULL_ENA | OMAP3_INPUT_EN)

/* 34xx off mode states */
#define OMAP34XX_PIN_OFF_NONE           0
#define OMAP34XX_PIN_OFF_OUTPUT_HIGH	(OMAP3_OFF_EN | OMAP3_OFFOUT_VAL)
#define OMAP34XX_PIN_OFF_OUTPUT_LOW	(OMAP3_OFF_EN)

#define OMAP34XX_PIN_OFF_INPUT          (OMAP3_OFF_EN | OMAP3_OFFOUT_ENn )
#define OMAP34XX_PIN_OFF_INPUT_PULLUP	(OMAP3_OFF_EN | OMAP3_OFFOUT_ENn | \
					 OMAP3_OFF_PULL_EN | OMAP3_OFF_PULL_UP)
#define OMAP34XX_PIN_OFF_INPUT_PULLDOWN	(OMAP3_OFF_EN | OMAP3_OFFOUT_ENn | \
					 OMAP3_OFF_PULL_EN)
#define OMAP34XX_PIN_OFF_WAKEUPENABLE	(OMAP3_OFFOUT_ENn | OMAP3_WAKEUP_EN)

#define MUX_CFG_34XX(desc, reg_offset, mux_value) {		\
	.name		= desc,					\
	.debug		= 0,					\
	.mux_reg	= reg_offset,				\
	.mux_val	= mux_value				\
},

struct pin_config {
	char 			*name;
	const unsigned int 	mux_reg;
	unsigned char		debug;

#if	defined(CONFIG_ARCH_OMAP34XX)
	u16			mux_val; /* Wake-up, off mode, pull, mux mode */
#endif


};



struct omap_mux_cfg {
	struct pin_config	*pins;
	unsigned long		size;
	int			(*cfg_reg)(const struct pin_config *cfg);
};

/* setup pin muxing in Linux */
extern int omap1_mux_init(void);
extern int omap2_mux_init(void);
extern int omap3_mux_init(void);
extern unsigned int omap_get_mux_reg(const char *mux_name);
extern int omap_mux_register(struct omap_mux_cfg *);
extern int omap_cfg_reg(const char *mux_name);


#endif
